package com.gmm.springboot.admin.mapper.test01;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface UserInfoMapper {
	@Select("select * from t_user_info where user_id=#{userId} limit 1 ")
	@Results(value = { @Result(property = "userId", column = "user_id"), @Result(property = "userName", column = "user_name"),
			@Result(property = "age", column = "age"), @Result(property = "registerTime", column = "register_time") })
	public UserInfo findRecordByKey(@Param("userId") Integer userId);

	@SelectProvider(method = "getSelectRecordSql", type = UserInfoSqlProvider.class)
	@Results(value = { @Result(property = "userId", column = "user_id"), @Result(property = "userName", column = "user_name"),
			@Result(property = "age", column = "age"), @Result(property = "registerTime", column = "register_time") })
	public List<UserInfo> findSelectRecordByMap(Map<String, Object> whereParams);

	@SelectProvider(type = UserInfoSqlProvider.class, method = "getSelectCountSql")
	public int findRecordsCount(Map<String, Object> whereParams);

	@Insert("INSERT INTO t_user_info  ( " + " user_name ,  age ,  register_time " + " )" + " VALUES ( " + " #{userName} ,  #{age} ,  #{registerTime} " + ")")
	@Options(useGeneratedKeys = true, keyProperty = "userId")
	public void addRecord(UserInfo record);

	@UpdateProvider(type = UserInfoSqlProvider.class, method = "getUpdateSql")
	public void updRecord(UserInfo record);

	@Delete("delete from t_user_info where user_id=#{userId}")
	public void delRecord(@Param("userId") Integer userId);
}
